<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8" %>
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro" %>

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>DP</title>

    <meta name="keywords" content="dayin">
    <meta name="description" content="dayin">

    <script language="javascript" src="js/LodopFuncs.js"></script>
    <link rel="stylesheet" type="text/css"
          href="easyui/themes/bootstrap/easyui.css">
    <link rel="stylesheet" type="text/css" href="easyui/themes/icon.css">

    <script type="text/javascript" src="easyui/jquery.min.js"></script>
    <script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="easyui/locale/easyui-lang-zh_CN.js"></script>
    <script src="js/yangshi.js"></script>
    <script>
        //获取当前网址，如： http://localhost:80/ybzx/index.jsp
        var curPath = window.document.location.href;
        //获取主机地址之后的目录，如： ybzx/index.jsp
        var pathName = window.document.location.pathname;
        //获取带"/"的项目名，如：/ybzx
        var path = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
    </script>
    <object id="LODOP_OB"
            classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=0 height=0>
        <embed id="LODOP_EM" type="application/x-print-lodop" width=0 height=0
               pluginspage="install_lodop32.exe"></embed>
    </object>

</head>
<body>
<input id='tailorid' type='hidden'
       value='<%=request.getParameter("tailorid")%>'>
<script type="text/javascript">
    $.ajax({
        url: path + '/production/diaopai/tailorid.do',
        data: {
            id: $('#tailorid').val()
        },
        type: 'POST',
        dataType: 'json',
        success: function (data) {
            $('#dg').datagrid('loadData', data)
        }
    })
</script>


<table id="dg" class="easyui-datagrid" title="打印吊牌"
       style="width: 100%; height: auto"
       data-options="
				iconCls: 'icon-edit',
				singleSelect: false,
				toolbar: '#tb',
				onDblClickRow: onClickRow
			">
    <thead>
    <tr>
        <th
                data-options="field:'sid',width:100,align:'center',checkbox:'true'"
                checked="true">ID
        </th>
        <th data-options="field:'product',width:100,align:'center'">商品款号</th>
        <th data-options="field:'productCode',width:100,align:'center'">商品编号</th>
        <th data-options="field:'colors',width:90,align:'center'">颜色</th>
        <th data-options="field:'sizes',width:90,align:'center'">尺码</th>
        <th data-options="field:'anquanjibie',width:180,align:'left',editor:'text'">安全级别</th>
        <th
                data-options="field:'zhixingbiaozhun',width:170,align:'left',editor:'text'">执行标准
        </th>
        <th
                data-options="field:'mianliao',width:170,align:'left',editor:'text'">面料明细
        </th>
        <th
                data-options="field:'liliao',width:170,align:'left',editor:'text'">里料
        </th>
        <th
                data-options="field:'tianchongwu',width:170,align:'left',editor:'text'">填充物
        </th>
        <th
                data-options="field:'zhuangliao',width:170,align:'left',editor:'text'">撞料
        </th>
        <th data-options="field:'productName',width:100,align:'center'">商品名称</th>
        <th data-options="field:'pinpai',width:90,align:'center'">商品品牌</th>
        <th data-options="field:'kuanshi',width:90,align:'center'">商品类型</th>
        <th
                data-options="field:'price',width:90,align:'right',formatter:function(value,row,index){
					 if(value!=null){
					    return value.toFixed(2)
					 }else{
					    return value
					 }
				}">铭牌价/￥
        </th>
        <th data-options="field:'shuliang',width:90,align:'right'">数量/件</th>
    </tr>
    </thead>
</table>


<div id="tb" style="height: auto">

    <a href="javascript:void(0)" class="easyui-linkbutton"
       data-options="iconCls:'icon-save',plain:true" onclick="accept()">保存</a>
    <!-- <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:true" onclick="selectAll()">全选</a> -->
    <a href="javascript:void(0)" class="easyui-linkbutton"
       data-options="iconCls:'icon-print',plain:true"
       onclick="prn_Preview()">打印预览</a>
    <!-- 	<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-print',plain:true" onclick="prn_Design()">打印设计</a> -->

    | 选择打印列:<select id='kx' class="easyui-combobox" name="language"
                    style="width: 300px"
                    data-options="
					valueField:'value',
					textField:'text',
					multiple:true,
					panelHeight:'auto'
			">
    <option value="0">执行标准</option>
    <option value="1">安全类别</option>
    <option value="2">面料</option>
    <option value="3">里料</option>
    <option value="4">撞料</option>
    <option value="5">填充物</option>
</select>


</div>


<script type="text/javascript">
    var kx = new Array("0", "1", "2", "3", "4", "5")
    $(function () {
        $('#kx').combobox('setValues', kx);

    })
    var editIndex = undefined;
    function endEditing() {
        if (editIndex == undefined) {
            return true
        }
        if ($('#dg').datagrid('validateRow', editIndex)) {
            /* var ed = $('#dg').datagrid('getEditor', {index:editIndex,field:'productid'});
             var productname = $(ed.target).combobox('getText');
             $('#dg').datagrid('getRows')[editIndex]['productname'] = productname; */
            $('#dg').datagrid('endEdit', editIndex);
            var rows = $("#dg").datagrid("getRows");
            var selections = $('#dg').datagrid('getSelections');//返回所有被选中的行
            for (var i = 0; i < selections.length; i++) {
                var sel = selections[i];
                var index = $('#dg').datagrid('getRowIndex', sel);
                $("#dg").datagrid("updateRow", {
                    index: index, //行索引
                    row: {
                        anquanjibie: rows[editIndex].anquanjibie, //行中的某个字段
                        zhixingbiaozhun: rows[editIndex].zhixingbiaozhun,
                        mianliao: rows[editIndex].mianliao,
                        liliao: rows[editIndex].liliao,
                        tianchongwu: rows[editIndex].tianchongwu,
                        zhuangliao: rows[editIndex].zhuangliao
                    }
                });
            }
            editIndex = undefined;
            return true;
        } else {
            return false;
        }
    }
    function onClickRow(index) {
        $('#dg').datagrid('clearSelections');
        if (editIndex != index) {
            if (endEditing()) {
                $('#dg').datagrid('selectRow', index).datagrid('beginEdit',
                    index);
                rowIndex = index;
                editIndex = index;
            } else {
                $('#dg').datagrid('selectRow', editIndex);
            }
        }
    }
    function append() {
        if (endEditing()) {
            $('#dg').datagrid('appendRow', {
                status: 'P'
            });
            editIndex = $('#dg').datagrid('getRows').length - 1;
            $('#dg').datagrid('selectRow', editIndex).datagrid('beginEdit',
                editIndex);
        }
    }

    function removeit() {
        if (editIndex == undefined) {
            return
        }
        $('#dg').datagrid('cancelEdit', editIndex).datagrid('deleteRow',
            editIndex);
        editIndex = undefined;
    }
    function accept() {
        if (endEditing()) {

        }
    }
    function reject() {
        $('#dg').datagrid('rejectChanges');
        editIndex = undefined;
    }
    function getChanges() {
        var rows = $('#dg').datagrid('getChanges');
        alert(rows.length + ' rows are changed!');
    }
</script>

<object id="LODOP1"
        classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=800
        height=400>
    <param name="Caption" value="显示区">
    <param name="Border" value="0">
    <param name="colors" value="white">
    <embed id="LODOP_EM1" TYPE="application/x-print-lodop" width=800
           height=400 border=0 color="white" PLUGINSPAGE="install_lodop.exe">
</object>


<script language="javascript" type="text/javascript">

    function alert(txt) {
        $.messager.alert('提示信息', txt)
    }
    var LODOP; //声明为全局变量
    function prn_Preview() {
        LODOP = getLodop();
        if ($('#dg').datagrid('getSelections').length != 0) {
            accept()
            /* LODOP.SET_PRINT_PAGESIZE(1,440,900,""); */
            LODOP.SET_PRINT_PAGESIZE(3, 455, 0, "");
            /* 	LODOP.SET_PRINT_MODE("POS_BASEON_PAPER",true); */
            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
            LODOP.SET_PRINT_STYLEA(2, "FontName", "黑体");
            CreateAllPages()

            /* LODOP.SET_PRINT_PAGESIZE(3,440,0,"");//这里3表示纵向打印且纸高“按内容的高度”；1385表示纸宽138.5mm；45表示页底空白4.5mm */
            LODOP.SET_PREVIEW_WINDOW(0, 0, 0, 0, 0, "");

            LODOP.PREVIEW();

        } else {
            alert("请选择要打印的内容")

        }
    };
    function prn_Design() {
        CreatePrintPage();
        LODOP.PRINT_DESIGN();
    };
    function CreatePrintPage() {
        LODOP = getLodop(document.getElementById('LODOP1'), document.getElementById('LODOP_EM1'));
        CreateAllPages();
    };


    function CreateAllPages() {
        var rows = $('#dg').datagrid('getSelections')
        var mianliao = '无';
        var liliao = '无';
        var tcw = '无';
        var zl = '无';
        var ck = '暂无';

        for (var i = 0; i < rows.length; i++) {
            if (rows[i].sizes == '90' || rows[i].sizes == '90/48') {

                ck = '2——3岁'
            }
            else if (rows[i].sizes == '100/52' || rows[i].sizes == '100') {

                ck = '3——4岁'
            } else if (rows[i].sizes == '110/56') {

                ck = '4——5岁'
            } else if (rows[i].sizes == '120/60') {

                ck = '6——7岁'
            } else if (rows[i].sizes == '130/64') {

                ck = '8——9岁'
            } else if (rows[i].sizes == '140/68') {

                ck = '10——11岁'
            } else if (rows[i].sizes == '150/72' || rows[i].sizes == '155/74') {

                ck = '12——13岁'
            } else if (rows[i].sizes == '160/76' || rows[i].sizes == '165/80' || rows[i].sizes == '165/78') {

                ck = '14——15岁'
            } else {
                ck = '————'
            }
            var ml = '';
            var zl = '';
            var ll = '';
            var tcw = '';
            var aqlb = '';
            var zxbz = '';

            if ($('#kx').combobox('getValues')[0] == 0) {

                zxbz = "<li style='font-size: x-small;margin-top: 1px;'>执行标准:" + rows[i].zhixingbiaozhun + "</li>"

            }
            if ($('#kx').combobox('getValues')[1] == 1) {

                aqlb = "<li style='font-size: x-small;margin-top: 1px;word-wrap:break-word; width:150px;'>安全类别:" + rows[i].anquanjibie + "</li>"
            }


            if (rows[i].mianliao != "" && $('#kx').combobox('getValues')[2] == 2) {
                ml = "<li  style='margin-top: 1px;font-size:10px;margin-top: 1px;font-weight: bold;width:150px;display:block;word-break: break-all;word-wrap: break-word;'>面 料:" + "<span style='font-size:9px;width:auto'>" + rows[i].mianliao + "</span></li>"
            }
            if (rows[i].zhuangliao != "" && $('#kx').combobox('getValues')[4] == 4) {
                zl = "<li  style='margin-top: 1px;font-size:10px;margin-top: 3px;font-weight: bold;width:150px;display:block;word-break: break-all;word-wrap: break-word;'>撞 料:" + "<span style='font-size:9px;width:auto'>" + rows[i].zhuangliao + "</span></li>"
            }
            if (rows[i].liliao != "" && $('#kx').combobox('getValues')[3] == 3) {
                ll = "<li  style='margin-top: 1px;font-size:10px;margin-top: 3px;font-weight: bold;width:150px;display:block;word-break: break-all;word-wrap: break-word;'>里 料:" + "<span style='font-size:9px;width:auto'>" + rows[i].liliao + "</span></li>"
            }
            if (rows[i].tianchongwu != "" && $('#kx').combobox('getValues')[5] == 5) {
                tcw = "<li  style='margin-top: 1px;font-size:10px;margin-top: 3px;font-weight: bold;width:150px;display:block;word-break: break-all;word-wrap: break-word;'>填充物:" + "<span style='font-size:9px;width:auto'>" + rows[i].tianchongwu + "</span></li></ul>"
            }
            LODOP.NewPage();
            LODOP.ADD_PRINT_HTML(95, 90, 73, 20, "<span style='border:1px solid black;transform:rotate(-45deg);position: absolute; top:35px;left:-3px;width:60px;height:15px;font-size: small;font-weight: bold;font-family:'黑体''>检(3)合格</span>");
            LODOP.ADD_PRINT_HTM(60, -40, 400, 19,
                "<ul style='list-style-type:none; margin-top: 10px;'>"
                + "<li style='margin-left: 40px; font-weight: 900;font-size:larger;'>合格证 </li>"
                + "<li style='margin-top: 1px; font-weight: bold;'>品 牌：" + rows[i].pinpai + "</li>"
                + "<li style='margin-top: 1px;font-weight: bold; '>款 号:<span style='font-size:12px'>" + rows[i].product + "</span></li>"
                + "<li style='margin-top: 1px;font-weight: bold;'>系 列：" + rows[i].kuanshi + "</li>"
                + "<li style='margin-top:2px;font-weight: bold;'>颜 色：" + rows[i].colors + "</li>"
                + "<li style='margin-top: 1px;font-weight: bold;'>品 名：" + rows[i].productName + "</li>"
                + zxbz
                + aqlb
                + "<li  style='margin-top: 1px;font-weight: bold;'>安全等级：合格品</li>"
                + "<li  style='margin-top: 1px;font-weight: bold;'>尺 码：<span style='font-size:20px'>" + rows[i].sizes + "</span></li>"
                + "<li  style='margin-top: 1px;margin-top: 1px;font-weight: bold;'>参 考：" + ck + "</li>"
                + ml
                + zl
                + ll
                + tcw);
            LODOP.ADD_PRINT_BARCODE(342, 0, 144, 44, "Code93", rows[i].productCode);
            LODOP.SET_PRINT_STYLE("FontSize", 10);
            LODOP.ADD_PRINT_TEXTA("text17", 390, 0, 169, 19, "统一零售价￥:" + rows[i].price.toFixed(2));
            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
            LODOP.SET_PRINT_STYLE("FontSize", 10);
        }
    };
</script>


<script type="text/javascript">
    function selectAll() {
        var rows = $('#dg').datagrid('getRows')
        for (var i = 0; i < rows.length; i++) {
            $('#dg').datagrid('selectRow', i);
        }
    }
</script>
</body>
</html>